/**
 * @Author: Your name
 * @Date:   2024-03-18 11:12:15
 * @Last Modified by:   Your name
 * @Last Modified time: 2024-03-19 15:45:23
 */
import 'package:flutter/material.dart';

class Tab2Content extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: ListView.builder(
        itemCount: 20,
        itemBuilder: (context, index) {
          return ListTile(
            leading: CircleAvatar(
              child: Text('${index + 1}'),
            ),
            title: Text('联系人 $index'),
            subtitle: Text('手机号码 $index'),
            onTap: () {
              print('点击了联系人 $index');
            },
          );
        },
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.search),
        onPressed: () {
          // 点击搜索按钮时导航到搜索页面
          Navigator.push(
            context,
            MaterialPageRoute(builder: (context) => SearchPage()),
          );
        },
      ),
    );
  }
}

class SearchPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('搜索页面'),
      ),
      body: Column(
        children: [
          SearchBox(), // 显示搜索框
          Expanded(
            child: SearchResultList(), // 显示搜索结果列表
          ),
        ],
      ),
    );
  }
}

class SearchBox extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.all(8.0),
      child: TextField(
        decoration: InputDecoration(
          hintText: '搜索联系人',
          prefixIcon: Icon(Icons.search),
          border: OutlineInputBorder(),
        ),
        onChanged: (value) {
          // 处理搜索框文本变化事件
          print('搜索框文本变化：$value');
        },
      ),
    );
  }
}

class SearchResultList extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // 模拟搜索结果
    List<String> searchResults = List.generate(10, (index) => '搜索结果 $index');

    return ListView.builder(
      itemCount: searchResults.length,
      itemBuilder: (context, index) {
        return ListTile(
          title: Text(searchResults[index]),
          onTap: () {
            // 处理搜索结果点击事件
            print('点击了搜索结果 $index');
          },
        );
      },
    );
  }
}
